<template>
  <div class="search">
    <div  v-for="item in props.searchMsg" :key="item.id">
      <div class="item" @click="clickSearchItem(item.title)">
        {{ item.title }}
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineProps, defineEmits } from "vue";
import { useRoute } from "vue-router";
type search = {
  id: number;
  title: string;
};
const route = useRoute();
const $emit = defineEmits(["clickSearchItemForBlog", "clickSearchItemForFriend"]);
const props = defineProps({
  searchMsg: {
    type: Array as () => Array<search>,
    default: [
      {
        id: 0,
        title: "",
      },
    ],
  },
});
const clickSearchItem = (title: string) => {
  if (route.path === "/index") {
    $emit("clickSearchItemForBlog", title);
  } else {
    $emit("clickSearchItemForFriend", title);
  }
};
</script>

<style lang="scss" scoped>
.search {
  position: absolute;
  margin-top: 15px;
  display: inline-block;
  border-radius: 10px;
  padding: 10px;
  width:170px;
  background-color: rgba(255, 255, 255, 0.9);
  z-index: 999;
}
.item {
  width: 170px;
  height: 30px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.5);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 35px;
  transition: all 0.3s;
  &:hover {
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 5px;
  }
}
.search::before {
  content: "";
  position: absolute;
  top: -20px;
  z-index: 19;
  border: 10px solid;
  border-color: transparent transparent rgba(255, 255, 255, 0.9);
}

@media screen and (max-width: 765px) {
  .search {
    position: absolute;
    margin-top: 15px;
    display: inline-block;
    border-radius: 10px;
    padding: 10px;
    background-color: rgba(255, 255, 255, 0.9);
    z-index: 99999999;
  }
}
</style>
